<template>
	<view class="content">
		<view class="login">
			<view class="login-top">登录</view>
			<view class="login-center clearfix">
				<view class="login-center-img"><image src="../../static/name.png" /></view>
				<view class="login-center-input">
					<input type="text" placeholder="请输入您的手机号" v-model="phone"/>
				</view>
			</view>
			<view class="login-center clearfix">
				<view class="login-center-img"><image src="../../static/password.png" /></view>
				<view class="login-center-input">
					<input type="password" placeholder="请输入您的密码" v-model="password"/>
				</view>
			</view>
      <view class="register" v-if="type=='seller'" @click="register">
        <text>去注册~</text>
      </view>
        <view class="login-button" @click="submit">登陆</view>

     
		</view>

    <u-toast ref="notice"></u-toast>

	</view>
</template>

<script>
export default {
	data() {
		return {
			phone:'',
			password:'',
      type:""
		};
	},
	onLoad(option) {
    this.type = option.type ? option.type : ""
    this.phone = option.phone ? option.phone : ""
    this.password = option.password ? option.password : ""
  },
	methods: {
		async submit(){

      let data = {
        mobile:this.phone,
        password:this.password
      }


	if(this.type == "seller")
	{
		   let result = await this.$u.api.user.acountlogin(data)
      if(result.code)
      {
        this.$refs.notice.show({
          type:"success",
          message:result.msg,
          duration:1200,
          
          complete:()=>
          {
            uni.$u.route({
              url:"pages/test/seller",
              params:{
                phone:this.phone,
                type:"seller",
                flag:"phone"
              }
            })
          }
        })
      }else
      {
        this.$refs.notice.show({
          type:"error",
          message:result.msg,
          duration:1200,
        
        })
      }

	}else if(this.type == "merchant")
	{
		   let result = await this.$u.api.user.adminlogin(data)
      if(result.code)
      {
        this.$refs.notice.show({
          type:"success",
          message:result.msg,
          duration:1200,
          
          complete:()=>
          {
            uni.$u.route({
              url:"pages/test/merchant",
              params:{
                phone:this.phone,
                type:"merchant",
                flag:"phone"
              }
            })
          }
        })
      }else
      {
        this.$refs.notice.show({
          type:"error",
          message:result.msg,
          duration:1200,
        
        })
      }
	}



   
		},
    register()
    {
      uni.$u.route({
        url:"pages/user/userform",
        params:{
          type:this.type
        }
      })

    },
    goto() {
			if(this.type=="business")
			{
				uni.$u.route({
				url: "pages/test/business",
        params:{
          type:this.type
        }
			})
			}else if(this.type=="seller")
			{
					uni.$u.route({
				url: "pages/test/seller",
        params:{
          type:this.type
        }
			})
			}else{
				
					uni.$u.route({
				url: "pages/test/merchant",
        params:{
          type:this.type
        }
			})
    }
  }
	}
};
</script>

<style lang="scss">
* {
	box-sizing: content-box;
}


.clearfix:after {
	visibility: hidden;
	display: block;
	font-size: 0;
	content: ' ';
	clear: both;
	height: 0;
}
.cli {
	clear: both;
	font-size: 0;
	height: 0;
	overflow: hidden;
	display: block;
}
.lclear {
	clear: left;
	font-size: 0;
	height: 0;
	overflow: hidden;
}
.fl {
	float: left;
}
.fr {
	float: right;
}
.content {
	display: flex;
	justify-content: center;
	align-items: center;
	overflow-y: hidden;
}
.login {
	width: 350px;
	border-radius: 5px;
	height: 500px;
	background: white;
}
.login-top {
	font-size: 24px;
	margin-top: 100px;
	padding-left: 40px;
	box-sizing: border-box;
	color: #333333;
	margin-bottom: 50px;
}
.login-center {
	width: 100%;
	box-sizing: border-box;
	padding: 0 40px;
	margin-bottom: 30px;
}
.login-center-img {
	width: 40rpx;
	height: 40rpx;
	float: left;
	margin-top: 5px;
}
.login-center-img > image {
	width: 100%;
	height: 100%;
}
.login-center-input {
	float: left;
	width: 230px;
	margin-left: 15px;
	height: 30px;
	position: relative;
}
.login-center-input input {
	z-index: 2;
	transition: all 0.5s;
	padding-left: 10px;
	color: #333333;
	width: 100%;
	height: 30px;
	border: 0;
	border-bottom: 1px solid #cccccc;
	border-top: 1px solid #ffffff;
	border-left: 1px solid #ffffff;
	border-right: 1px solid #ffffff;
	box-sizing: border-box;
	outline: none;
	position: relative;
}
.login-center-input input:focus {
	border: 1px solid dodgerblue;
}
.login-center-input-text {
	background: white;
	padding: 0 5px;
	position: absolute;
	z-index: 0;
	opacity: 0;
	height: 20px;
	top: 50%;
	margin-top: -10px;
	font-size: 14px;
	left: 5px;
	color: dodgerblue;
	line-height: 20px;
}

  .login-button {
    cursor: pointer;
    width:350px;
    text-align: center;
    height: 40px;
    line-height: 40px;
    background-color: dodgerblue;
    border-radius: 5px;
    margin-top: 50px;
    color: white;
  
 

  
  
}

.register{
  color:#3c9cff;
  padding-left: 35px;
  font-size: 13px;

}
</style>

